package com.mc.lp.database.service.handler;

import java.util.HashSet;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;

import com.mc.lp.database.exception.ConcurrentAccessException;
import com.mc.lp.database.service.handler.constant.FormRequestType;
import com.mc.lp.service.MicroCampusEntityService;
import com.mc.lp.service.RegistrationService;
import com.mc.lp.service.UserService;
import com.mc.lp.shared.util.constants.ResponseStatus;
import com.mc.lp.shared.vo.IValueObject;
import com.mc.lp.shared.vo.RegistrationVO;
import com.mc.lp.shared.vo.ServiceResponse;
import com.mc.lp.shared.vo.SimpleResponse;

/**
 * handler all request related to Registration records saving and fetching
 * information.
 * 
 * @author aphanda
 * 
 */
public class RegistrationHandler extends AbstractFormHandler<IValueObject, IValueObject> {

	
	@Resource
	RegistrationService registrationService;
	
	@Resource
	MicroCampusEntityService microCampusEntityService;
	
	@Resource
	UserService userService;
	
	
	/**
	 * this method will tell how many request this handler can handle
	 */
	public HashSet<FormRequestType> getRequestHandlingType() {
		HashSet<FormRequestType> handledRequest = new HashSet<FormRequestType>();
		
		// SAVE Registration
		handledRequest.add(FormRequestType.REGISTER);
		// Cancel Registration by deleting entry from table and childs as well
		handledRequest.add(FormRequestType.CANCEL_REGISTRATION);
		// Add student in already added Parent
		handledRequest.add(FormRequestType.ADD_STUDENT);
		// Delete student in already added parent. Please note ONLY SOFT DELETE as we may require all the acads data
		handledRequest.add(FormRequestType.DELETE_STUDENT);
		// Update core registration details i.e. start date, end date, registered by and register date and unique Registration number
		handledRequest.add(FormRequestType.UPDATE_REGISTRATION);
		return handledRequest;
	}

	@Override
	public IValueObject serveRequest(FormRequestType requestType, IValueObject object) throws DataAccessException, ConcurrentAccessException {
		SimpleResponse response = new SimpleResponse();
		response.setId(1);
		response.setMsg("No case matched to perform operation, please check request type");

		switch (requestType) {
		case REGISTER: // you will get RegistrationVO, this is insert
			return SaveRegistration(requestType, (RegistrationVO) object);
		case CANCEL_REGISTRATION: 
			return cancelRegistration(requestType, (RegistrationVO) object);
		case UPDATE_REGISTRATION: 
			return updateRegistration(requestType, (RegistrationVO) object);
		default:
			break;
		}
		return response;
	}

	private IValueObject SaveRegistration(FormRequestType requestType, RegistrationVO object) {
		ServiceResponse<RegistrationVO> response = new ServiceResponse<RegistrationVO>();
		response.setStatus(ResponseStatus.SUCCESS);
		response.setMsg("Deleted successfully");

	
	return response;
	}

	private IValueObject cancelRegistration(FormRequestType requestType, RegistrationVO object) {
		// TODO Auto-generated method stub
		ServiceResponse<RegistrationVO> response = new ServiceResponse<RegistrationVO>();
		response.setStatus(ResponseStatus.SUCCESS);
		response.setMsg("Deleted successfully");

	
	return response;
	}

	private IValueObject updateRegistration(FormRequestType requestType, RegistrationVO object) {
		ServiceResponse<RegistrationVO> response = new ServiceResponse<RegistrationVO>();
			response.setStatus(ResponseStatus.SUCCESS);
			response.setMsg("Deleted successfully");

		
		return response;
	}

}
